<?php


/**
 * 前后台公共辅助函数库
 */


//------------------------------------------------------------------------------
function Iif($expression, $returntrue, $returnfalse = ''){
	if($expression){
		return $returntrue;
	}else{
		return $returnfalse;
	}
}


//------------------------------------------------------------------------------
function ForceInt($InValue, $DefaultValue = 0) {
	$iReturn = intval($InValue);
	return ($iReturn == 0) ? $DefaultValue : $iReturn;
}


//------------------------------------------------------------------------------
function ForceIntFrom($VariableName, $DefaultValue = 0) {
	if (isset($_GET[$VariableName])) {
		return ForceInt($_GET[$VariableName], $DefaultValue);
	} elseif (isset($_POST[$VariableName])) {
		return ForceInt($_POST[$VariableName], $DefaultValue);
	} else {
		return $DefaultValue;
	}
}


//------------------------------------------------------------------------------
function IsGet($VariableName) {
	if (isset($_GET[$VariableName])) {
		return true;
	} else {
		return false;
	}

}


//------------------------------------------------------------------------------
function IsPost($VariableName) {
	if (isset($_POST[$VariableName])) {
		return true;
	} else {
		return false;
	}
}


//------------------------------------------------------------------------------
function PassGen($length = 8){
	$str = 'abcdefghijkmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	for ($i = 0, $passwd = ''; $i < $length; $i++)
		$passwd .= substr($str, mt_rand(0, strlen($str) - 1), 1);
	return $passwd;
}


//------------------------------------------------------------------------------
//获取某类中的所有public方法（不包括其父类中的方法）
 function get_this_class_methods($class){

     $array1 = get_class_methods($class);

     if($parent_class = get_parent_class($class))
	 {
         $array2 = get_class_methods($parent_class);
         $array3 = array_diff($array1, $array2);
     }
	 else
	 {
         $array3 = $array1;
     }

     return($array3);
 } 



function object_to_array($data)
{
    if (is_array($data) || is_object($data))
    {
        $result = array();
        foreach ($data as $key => $value)
        {
            $result[$key] = object_to_array($value);
        }
        return $result;
    }
    return $data;
}
